﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TemplatePatterns;
using WithDelegats;

namespace Sorting
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Bubble sorting using template method pattern:");
            TemplateSorting();
            
            Console.WriteLine("Bubble sorting using delegats:");
            DelegatesSorting();
            
            Console.ReadKey();
        }

        #region  Sorting of mass-s using Delegates

        /// <summary>
        /// Sorting of mass-s using Delegates
        /// </summary>
        private static void DelegatesSorting()
        {
            DelegatesSortingMassOfInts();
            DelegatesSortingMassOfPerson();
        }

        /// <summary>
        /// Ascending and descending sortings mass of persons
        /// </summary>
        private static void DelegatesSortingMassOfPerson()
        {
            Console.WriteLine("Ascending sorting mas of persons");
            Sortings<Person> delegIntA = new Sortings<Person>("asc");
            Person[] massPA = Person.GetMassPersons();

            delegIntA.Sort(ref massPA);
            Printer<Person>.PrintMass(massPA);

            Console.WriteLine();
            Console.WriteLine("Descending sorting mas of persons");

            Sortings<Person> delegIntB = new Sortings<Person>("des");
            Person[] massPB = Person.GetMassPersons();

            delegIntB.Sort(ref massPB);
            Printer<Person>.PrintMass(massPB);

            Console.WriteLine();
        }

        /// <summary>
        /// Ascending and descending sortings mass of int-s
        /// </summary>
        private static void DelegatesSortingMassOfInts()
        {
            Console.WriteLine("Ascending sorting mas of int-s");
            Sortings<int> delegIntA = new Sortings<int>("asc");
            int[] massA = GetMassInts();

            delegIntA.Sort(ref massA);
            Printer<int>.PrintMass(massA);

            Console.WriteLine();
            Console.WriteLine("Descending sorting mas of int-s");

            Sortings<int> delegIntB = new Sortings<int>("des");
            int[] massB = GetMassInts();

            delegIntB.Sort(ref massB);
            Printer<int>.PrintMass(massB);

            Console.WriteLine();
        }

        #endregion

        #region Sorting of mass-s using Template pattern

        /// <summary>
        /// Sorting of mass-s using Template pattern
        /// </summary>
        private static void TemplateSorting()
        {
            TemplateSortingMassOfInts();
            TemplateSortingMassOfPerson();
        }

        /// <summary>
        /// Ascending and descending sortings mass of int-s
        /// </summary>
        private static void TemplateSortingMassOfInts()
        {
            Console.WriteLine("Ascending sorting mas of int-s");
            TemplateSorting<int> tempIntA = new AscendingSorting<int>();
            int[] massA = GetMassInts();

            tempIntA.Sort(ref massA);
            Printer<int>.PrintMass(massA);

            Console.WriteLine();
            Console.WriteLine("Descending sorting mas of int-s");

            TemplateSorting<int> tempIntB = new DescendingSorting<int>();
            int[] massB = GetMassInts();

            tempIntB.Sort(ref massB);
            Printer<int>.PrintMass(massB);

            Console.WriteLine();
        }

        /// <summary>
        /// Ascending and descending sortings mass of persons
        /// </summary>
        private static void TemplateSortingMassOfPerson()
        {
            Console.WriteLine("Ascending sorting mas of persons");
            TemplateSorting<Person> tempIntPA = new AscendingSorting<Person>();
            Person[] massPA = Person.GetMassPersons();

            tempIntPA.Sort(ref massPA);
            Printer<Person>.PrintMass(massPA);

            Console.WriteLine();
            Console.WriteLine("Descending sorting mas of persons");

            TemplateSorting<Person> tempInt = new AscendingSorting<Person>();
            Person[] massPB = Person.GetMassPersons();

            tempInt.Sort(ref massPB);
            Printer<Person>.PrintMass(massPB);

            Console.WriteLine();
        }

        #endregion

        /// <summary>
        /// Get mass of ints
        /// </summary>
        /// <returns>Mass of int-s</returns>
        private static int[] GetMassInts()
        {
            return new int[] { 12, 12, 23, 34, 567, 789, 8890, 890, 2, 890, -23, 345 };
        }
    }
}
